#include"processBar.h"

#define BLUE  "\033[1;34m"
#define NONE  "\033[m"

const char* label = "|/-\\-";

//void processbar(int speed)
//{
//    char Bar[NUM] = {0};
//    int cnt =  0;
//    int len = strlen(label);
//    while(cnt <= 100)
//    {
//        printf("[%-100s][%d%%][%c]\r", Bar, cnt, label[cnt%len]);
//        fflush(stdout);
//        Bar[cnt++] = STYLE;
//        if(cnt <= TOP )
//            Bar[cnt] = RIGHT;
//        usleep(speed);
//    }
//    printf("\n");
//}


char Bar[NUM] = {0};
void processbar(int rate)
{

    if(rate < 0 || rate > 100)
        return;

    int len = strlen(label);
    printf(BLUE"[%-100s]"NONE"[%d%%][%c]\r", Bar, rate, label[rate%len]);
    fflush(stdout);
    Bar[rate++] = STYLE;
    if(rate <= TOP )
        Bar[rate] = RIGHT;
}

void init()
{
    memset(Bar,'\0',sizeof(Bar));
}
